package struct.scene.items
{
	import com.common.displayObjects.ComponentChildren;
	import com.common.utils.Clock;
	
	import data.GridVO;
	
	import flash.display.Graphics;
	import flash.display.Shape;
	import flash.events.Event;
	
	/**
	 * 地格  
	 * @author Administrator
	 * 
	 */	
	public class Grid extends ComponentChildren
	{
		public var xIndex:int; //x轴方向的index
		public var yIndex:int;//y轴方向的index
		public var isRoad:Boolean; //是否是 路
		public var gridVO:GridVO;
		
		public function Grid(_w:Number, _h:Number, xIndex:int, yIndex:int, isRoad:Boolean, gridVO:GridVO)
		{
			this.xIndex = xIndex;
			this.yIndex = yIndex;
			this.isRoad = isRoad;
			this.gridVO = gridVO;
			super(_w, _h);
		}

		override protected function createChildren():void
		{
			super.createChildren();
			var g:Graphics = graphics;
			g.beginFill(0x000, 0.5);
			g.drawRect(0, 0, width, height);
			if (isRoad)
			{
				g.beginFill(0x00ff00, 0.5);
			}else
			{
				g.beginFill(0xff0000, 0.5);
			}
			g.drawRect(1, 1, width -2, height-2);
			g.endFill();
		}
		
		public var mapItem:MapItem;
		public function addItem(mapItem:MapItem):void
		{
			this.mapItem = mapItem;
			mapItem.x = width * .5;
			mapItem.y = height * .5;
			addChild(mapItem);
		}
		
		public function removeitem():MapItem
		{
			removeChild(mapItem);
			var item:MapItem = mapItem;
			mapItem = null;
			return item;
		}
		
		public function hasMapItem():Boolean
		{
			return mapItem? true:false;
		}
	}
}